// 为了0416迭代上线，重构此文件
import React from 'react';
import {connect} from 'react-redux';
import {Form, Switch, Icon, Input, Button, Row, Col, message, DatePicker, Select, Tooltip} from 'antd';
import moment from "moment";
import config from 'config';
import companyMaintainService from 'containers/enterprise-manage/company-maintain/company-maintain.service';
import {messages, deepCopy} from "share/common";
import Selector from 'components/selector';
import 'styles/enterprise-manage/company-maintain/new-company-maintain.scss';
import {LanguageInput} from 'components/index';
import mainService from 'containers/main.service';
import PDService from 'containers/enterprise-manage/person-manage/person-detail/person-detail.service';
import Chooser from 'components/chooser';
import { parse } from 'path';
import {companyAttributeList} from 'containers/enterprise-manage/company-maintain/company-manage.model';

const Option = Select.Option;
const FormItem = Form.Item;

class WrappedNewCompanyMaintain extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      selectedKeysDepDataByApi: {},
      companyDetail: {
        companyOID: null,
        companyCode: null,//公司代码
        countryName: "",
        countryCode: null,
        name: "",//公司名称
        companyTypeId: "4993798",//类型后端已经默认：业务实体
        companyTypeName: "",//类型后端已经默认：业务实体
        companyLevelId: null,//公司级别
        companyLevelName: "",//公司级别名称：用于显示
        legalEntityId: null,//法人
        legalEntityName: "",//法人名称：用于显示
        parentCompanyId: null,//非比填:上级公司
        parentCompanyName: "",//非比填:上级公司：用于显示
        setOfBooksId: null,//账套,也不用上传，默认是法人一个账套
        setOfBooksName: "",//账套：用于显示
        startDateActive: null,//有效期从
        endDateActive: null,//有效期到
        address: "",//非比填
        enabled: true,//状态
        i18n: {},//名称
        companyAttribute: null, //公司属性
      },
      loading: false,
      //公司级别下拉单
      selectListCompanyLevel: {
        url: `${config.baseUrl}/api/companyLevel/selectByTenantId`,
        label: record => `${record.description}`,
        key: 'id',
      },
      //法人下拉单
      selectListLegalEntity: {
        // isAll=false 是否需要过滤掉已经挂了公司的法人 后端逻辑判断只针对老权限
        url: `${config.baseUrl}/api/all/legalentitys?isAll=false`,
        label: record => `${record.entityName}`,
        key: 'id',
      },
      //上级公司：需要过滤本公司与法人实体对应的公司，
      selectListParentCompany: [],
      //账套
      selectListSob: {
        url: `${config.baseUrl}/api/setOfBooks/by/tenant`,
        label: record => `${record.setOfBooksName}`,
        key: 'id',
      },
      flag: true
    };
  }
  handleSelectChange = (value) => {
    this.setState({
      flag: value === 0 ? false : true
    }, () => {
      if (this.state.flag) {//市场
        if(this.state.companyDetail.companyAttribute !== null){
          if(this.state.companyDetail.companyAttribute){//市场
            this.props.form.setFieldsValue({area: [{messageKey: this.state.companyDetail.area, id: this.state.companyDetail.area}]})
            this.props.form.setFieldsValue({market: [{messageKey: this.state.companyDetail.market, id: this.state.companyDetail.market}]})
          }else {
            this.props.form.setFieldsValue({area: []})
            this.props.form.setFieldsValue({market: []})
          }
        }
      }else {//非市场
        if(this.state.companyDetail.companyAttribute !== null){
          if(this.state.companyDetail.companyAttribute){
            this.props.form.setFieldsValue({area: null})
            this.props.form.setFieldsValue({market: null})
          }else{
            this.props.form.setFieldsValue({area: this.state.companyDetail.area})
            this.props.form.setFieldsValue({market: this.state.companyDetail.market})
          }
        }else {
          this.props.form.setFieldsValue({area: null})
          this.props.form.setFieldsValue({market: null})
        }
      }
    })

  }

  componentDidMount() {
    if (this.props.params.flag === 'create') {
      this.getSelectListParentCompany();
    } else {
      this.getCompanyById(this.props.params.flag);
    }
  }

  handleFinancialPreSelect = (value) => {
    console.log("value",value[0].employeeID)
    if(typeof value !== 'undefined'){
      if (value.length > 0) {
        this.setState({
          financialPreId : value[0].employeeID
        });
      }
    }
  }

  handleFinancialReviewSelect = (value) => {
    console.log("value",value[0].employeeID)
    if(typeof value !== 'undefined'){
      if (value.length > 0) {
        this.setState({
          financialReviewId : value[0].employeeID
        });
      }
    }
  }

  onAreaChange = changedValue => {
    const companyDetail = {...this.state.companyDetail}
    if(changedValue.length>0){
      //如果新选择的区域不与原本选择的区域一致，为了市场匹配区域，清空市场的值
      if(changedValue[0].messageKey !== this.state.companyDetail.area){
        this.props.form.setFieldsValue({market: []})
        //改变查询市场时传入的区域area值
        companyDetail.area = changedValue[0].messageKey
        this.setState({ companyDetail:companyDetail});
        console.log("改变后的区域值：",this.state.companyDetail.area)
      }
    }
  };

  //获取公司详情：如果是编辑
  getCompanyById = (id) => {
    companyMaintainService.getCompanyById(id)
      .then((res) => {
        this.setState({
          companyDetail: res.data,
          flag: res.data.companyAttribute === null ? true : res.data.companyAttribute
        },()=>{
          this.getSelectListParentCompany(this.state.companyDetail.legalEntityId,this.props.params.companyOID);
          if (res.data.customFormValues && res.data.customFormValues.length > 0) {
            this.getPersonDetailEnumerationList();
          }
        })
      })
  }

  getSelectListParentCompany = (legalEntityId,companyOID) => {
    let params = {
      legalEntityId: legalEntityId ? legalEntityId : 0,
      filterCompanyOIDs: companyOID ? companyOID : null
    }
    companyMaintainService.getSelectListParentCompany(params)
      .then((res) => {
        let selectListParentCompany = this.state.selectListParentCompany;
        selectListParentCompany = res.data;
        this.setState({
          selectListParentCompany
        })
      })
  }
  // 这里借用人员扩展字段
  // 把表单的值设置到人员信息扩展字段里面去
  setFromToCustomFormValues = (values) => {
    let customFormValues = this.state.companyDetail.customFormValues;
    if (customFormValues) {
      for (let key in values) {
        for (let i = 0; i < customFormValues.length; i++) {
          if (customFormValues[i].fieldOID === key) {
            if (customFormValues[i].messageKey === "common.date") {
              customFormValues[i].value = values[key] ? new Date(moment(values[key]).format("YYYY-MM-DD")) : "";
            } else if (customFormValues[i].messageKey === "time") {
              if (values[key]) {
                customFormValues[i].value = moment(values[key]).format("HH:mm");
              } else {
                customFormValues[i].value = "";
              }
            } else if (customFormValues[i].messageKey === "image") {
              //把attachmentImages赋值，只是为了前端展示
              customFormValues[i].attachmentImages = values[key];
              //这个地方要注意一下 服务端返回的图片字段是attachmentImages
              //但是上传的时候是attachments
              customFormValues[i].attachments = values[key];
              //还需要把value设置一下
              if (customFormValues[i].attachments) {
                let _values = [];
                for (let j = 0; j < customFormValues[i].attachments.length; j++) {
                  _values.push(customFormValues[i].attachments[j].attachmentOID);
                }
                customFormValues[i].value = JSON.stringify(_values);
              }
            } else {
              let t = this.getValueByMessageKey(values, key, customFormValues);
              customFormValues[i].value = t ? t : values[key];
            }
          }
        }
      }
    }
  }
  getValueByMessageKey = (values, key, customFormValues) => {
    for(let i = 0; i < customFormValues.length; i++){
      if(customFormValues[i].fieldOID === key){
        if(customFormValues[i].messageKey === "cust_list" &&
          customFormValues[i].customEnumerationList &&
          customFormValues[i].customEnumerationList.values &&
          customFormValues[i].customEnumerationList.values.length
        ){
          let list = customFormValues[i].customEnumerationList.values;
          for(let i = 0; i < list.length; i++){
            if(list[i].messageKey === values[key]){
              return list[i].value;
            }
          }
        }
      }
    }
  }
  /*
  * 这个地方借用人员信息扩展字段列表数据封装
  * 获取扩展字段中的值列表
  * */
 getPersonDetailEnumerationList = () => {
  let companyObj = this.state.companyDetail;
  let customFormValues = companyObj.customFormValues;
  for (let i = 0; i < customFormValues.length; i++) {
    if (customFormValues[i].messageKey === "cust_list") {
      let dataSource = null;
      try {
        dataSource = JSON.parse(customFormValues[i].dataSource);
      } catch (e) {
      }
      if (dataSource && dataSource.customEnumerationOID) {
        PDService.getListByCustomEnumerationOID(dataSource.customEnumerationOID)
          .then((res) => {
            this.setPersonDetailEnumerationList(res.data, customFormValues[i])
          })
      }
    }
  }
}
/*
* 这个地方借用人员信息扩展字段列表数据封装
* 设置扩展字段中的值列表
* 把值列表挂在对应字段上
* */
setPersonDetailEnumerationList = (customEnumerationList, filed) => {
  let companyObj = deepCopy(this.state.companyDetail);
  let customFormValues = companyObj.customFormValues;
  for (let i = 0; i < customFormValues.length; i++) {
    if (customFormValues[i].fieldOID === filed.fieldOID) {
      customFormValues[i].customEnumerationList = customEnumerationList;
      /*
      * 这里应该不会涉及与其他系统进行同步，如果要与其他系统同步
      * 则需要：
      * 每设置一次，都需要更新一下
      * 后端可能返回的是值列表值对应的 code（value），不是 messageKey，需要找一下
      * 参见 bug13014
      * */
      this.setState({
        companyDetail: companyObj
      })
    }
  }
};
  //保存新建公司
  handleSave = (e) => {
    e.preventDefault();
    let _company = this.state.companyDetail;
    this.props.form.validateFieldsAndScroll((err, values) => {
      console.log(values)
      if (!err) {
        this.setFromToCustomFormValues(values);
        if (!_company.startDateActive) {
          //请选择有效期从
          message.warning(messages('enterprise-manage.key335')/*请选择有效期从*/);
          return;
        }

        if(Array.isArray(values.area)){
          if (values.area.length > 0) {
            if (values.area[0].id) {
              values.area = values.area[0].messageKey
            }
          }else {
            values.area = null
          }
        }

        if(Array.isArray(values.market)){
          if (values.market.length > 0) {
            if (values.market[0].id) {
              values.market = values.market[0].messageKey
            }
          }else{
            values.market = null
          }
        }

        values.startDateActive = values.startDateActive.format();
        if (values.endDateActive) {
          values.endDateActive = values.endDateActive.format();
        }
        if(values.countryCode === _company.countryName){
          values.countryCode = _company.countryCode;
        }
        if(values.legalEntityId === _company.legalEntityName){
          values.legalEntityId = _company.legalEntityId;
        }
        if(values.companyLevelId === _company.companyLevelName){
          values.companyLevelId = _company.companyLevelId;
        }else {
          _company.companyLevelId = values.companyLevelId;
        }
        if(values.parentCompanyId === _company.parentCompanyName){
          //进入页面，未修改
          values.parentCompanyId = _company.parentCompanyId;
        }else {
          //修改后
          _company.parentCompanyId = values.parentCompanyId;
        }
        values.name = _company.name;
        values.i18n = _company.i18n;
        if (_company.id && _company.companyOID) {
          //当删除某一个字段的时候，values 为null，导致没有覆盖原有属性
          let company = Object.assign(_company, values)
          if(company.companyLevelId === null || company.companyLevelId === undefined){
            company.companyLevelName = null;
            company.companyLevelId = null
          }
          if(company.parentCompanyId === null || company.parentCompanyId === undefined){
            company.parentCompanyName = null;
            company.parentCompanyId = null;
          }
          company.financialPreId = this.state.financialPreId;
          company.financialReviewId = this.state.financialReviewId;
          // console.log(company)
          this.updateCompany(company)
        } else {
          values.financialPreId = this.state.financialPreId;
          values.financialReviewId = this.state.financialReviewId;
          this.addCompany(values)
        }
      }
    });
  };
  //新增公司
  addCompany = (company) => {
    this.setState({
      loading: true,
    })
    companyMaintainService.addCompany(company)
      .then(response => {
        this.setState({
          loading: false,
        })
        mainService.getAvailableCompany();
        this.context.router.goBack();
      }).catch(err => {
      this.setState({
        loading: false,
      })
    })
  }

  //编辑公司
  updateCompany = (company) => {
    this.setState({
      loading: true,
    })
    companyMaintainService.updateCompany(company)
      .then(response => {
        this.setState({
          loading: false,
        })
        this.context.router.goBack();
      }).catch(err => {
      this.setState({
        loading: false,
      })
    })
  }
  //返回
  handleCancel = () => {
    this.context.router.goBack();
  };
  //不能大于endDate
  disabledStartDate = (startValue) => {
    let {companyDetail} = this.state;
    let endValue = companyDetail.endDateActive;
    if (!startValue || !endValue) {
      return false;
    }
    return startValue.valueOf() > endValue.valueOf();
  }
  //不能小于于startDate
  disabledEndDate = (endValue) => {
    let {companyDetail} = this.state;
    let startValue = companyDetail.startDateActive;
    if (!endValue || !startValue) {
      return false;
    }
    return endValue.valueOf() <= startValue.valueOf();
  }
  onStartTimeChange = (val) => {
    let {companyDetail} = this.state;
    companyDetail.startDateActive = val;
    this.setState({
      companyDetail
    })
  }
  onEndTimeChange = (val) => {
    let {companyDetail} = this.state;
    companyDetail.endDateActive = val;
    this.setState({
      companyDetail
    })
  }
  //监听表单值
  handleChange = (e) => {
    if (this.state.loading) {
      this.setState({
        loading: false,
      })
    }
  };

  legalEntityIdChange = (legalEntityId) => {
    this.getSelectListParentCompany(legalEntityId);
  }
  countryCodeChange=(value)=>{

  }
  renderParentCompanyList = (list) => {
    if (list.length > 0) {
      return (
        <Select showSearch placeholder={messages("common.select")} allowClear={true}>
          {list.map((item) => <Option value={item.id} key={item.id}>{item.name}</Option>)}
        </Select>
      )
    }
    else {
      return (
        <Select placeholder={messages("common.select")} disabled={true}/>
      )
    }
  };

  //公司属性选择框
  renderCompanyAttributeList = () => {
    return (
      <Select placeholder={messages("common.please.select")} allowClear={false} onChange={this.handleSelectChange}>
        {companyAttributeList.map((item) => <Option value={item.value} key={item.value}>{item.label}</Option>)}
      </Select>
    )
  };

  //多语言
  i18nCompanyNameChange = (name, i18nName) => {
    const {companyDetail} = this.state;
    companyDetail.name = name;
    if(!companyDetail.i18n) {
      companyDetail.i18n = {}
    }
    companyDetail.i18n.name = i18nName;
    this.setState({companyDetail})
  };

  renderExtendFiledEditing = () => {
    let dep = this.state.companyDetail;
    let values = dep.customFormValues ? dep.customFormValues : [];
    return <div className="extend-field-edit-wrap">
      <div className="extend-field-title">{messages('enterprise-manage.key153'/*扩展字段*/)}
        <Tooltip title={messages('enterprise-manage.key401')/*可在企业管理-公司管理-公司扩展字段进行编辑公司扩展字段*/}>
          <Icon style={{marginLeft: '10px'}} type="question-circle-o"/>
        </Tooltip>
      </div>
      <Row gutter={24}>
        {this.renderEditingField(values)}
      </Row>
    </div>
  }
  // -----扩展字段 编辑状态---start
  renderEditingField = (values) => {
    let dom = [];
    for (let i = 0; i < values.length; i++) {
      dom.push(this.renderEditingContentByMessageKey(values[i]))
    }
    return dom;
  }
  renderEditingContentByMessageKey = (field) => {
    let messageKey = field.messageKey;
    //分为：单行输入框，多行输入框，值列表，日期，数字，时间，图片
    switch (messageKey) {
      case "input": {
        return this.renderEditingFiled_input(field);
        break;
      }
      case "cust_list": {
        return this.renderEditingFiled_cust_list(field);
        break;
      }
    }
  }
  renderEditingFiled_input = (field) => {
    const {getFieldDecorator} = this.props.form;
    return (
      <Col span={8}>
        <FormItem
          key={field.fieldOID}
          label={field.fieldName}
          colon={true}>
          {getFieldDecorator(field.fieldOID, {
            initialValue: field.value,
            rules: [
              {
                max: 50,
                message: messages('enterprise-manage.key155'/*最多输入50个字符*/)
              },
              {
                required: field.required,
                message: messages('common.please.enter')
              }
            ]
          })(
            <Input placeholder={messages('common.please.enter')}/>)
          }
        </FormItem>
      </Col>
    )
  }
  renderEditingFiled_cust_list = (field) => {
    const {getFieldDecorator} = this.props.form;
    //如果是值列表类型，在返回的数据上，前端多挂了一个customEnumerationList属性，
    //这个选择列表就从这个属性上拿了
    return (
      <Col span={8}>
        <FormItem
          key={field.fieldOID}
          label={field.fieldName}
          colon={true}>
          {getFieldDecorator(field.fieldOID, {
            initialValue: field.value,
            rules: [
              {
                required: field.required,
                message: messages('common.please.enter')
              }
            ]
          })(
            <Select>
              {field.customEnumerationList && _renderCustomEnumerationList(field.customEnumerationList.values)}
            </Select>
          )
          }
        </FormItem>
      </Col>
    )

    //渲染值列表
    function _renderCustomEnumerationList(list) {
      let dom = [];
      if (list.length > 0) {
        list.map(function (item) {
          /*
           * 要做多语言，这个地方上传 code，后端返回的时候，任然是 messageKey，所以显示的时候用 messageKey 去查 value 显示
           * code 值可以是 null，所以传 value，值列表的 value 就是 code
           * 之前上传的是 messageKey
           * dom.push(<Option key={item.id} value={item.messageKey}>{item.messageKey}</Option>)
           * */
          dom.push(<Option key={item.id} value={item.value}>{item.messageKey}</Option>)
        });
        return dom;
      } else {
        return ("");
      }
    }
  }
  render() {
    const {getFieldDecorator} = this.props.form;
    const {companyDetail, loading} = this.state;
    return (

      <div className="new-company-maintain-warp">
        <Form onSubmit={this.handleSave} onChange={this.handleChange}>
          <Row gutter={24} className="new-lp-row-wrap">
            <Col span={8}>
              <FormItem
                label={messages('enterprise-manage.key24'/*公司代码*/)}//公司代码
                colon={true}>
                {getFieldDecorator('companyCode', {
                  initialValue: companyDetail.companyCode,
                  rules: [
                    {
                      required: true,
                      message: messages("common.please.enter")
                    },
                    {
                      max: 35,
                      message: messages('enterprise-manage.key50'/*不能超过35个字符*/)                    },
                  ]
                })(
                  <Input
                    disabled={companyDetail.companyCode}
                    placeholder={messages("common.please.enter")}/>)
                }
              </FormItem>
            </Col>
            <Col span={8}>
              <div className="new-lp-row">
                <span className="new-lp-row-re">*</span>
                <span>
                  {messages('enterprise-manage.key25'/*公司名称*/)}：
                </span>
              </div>
              <LanguageInput
                key={1}
                name={companyDetail.name}
                i18nName={companyDetail.i18n&&companyDetail.i18n.name ? companyDetail.i18n.name : null}
                isEdit={companyDetail.id}
                nameChange={this.i18nCompanyNameChange}
              />
            </Col>
            <Col span={8}>
              <FormItem
                label={messages('enterprise-manage.key27'/*公司级别*/)} /* 公司级别*/
                colon={true}>
                {getFieldDecorator('companyLevelId', {
                  initialValue: companyDetail.companyLevelName,
                })(
                  <Selector
                    placeholder={messages("common.please.select")}
                    selectorItem={this.state.selectListCompanyLevel}/>
                )
                }
              </FormItem>

            </Col>
          </Row>
          <Row gutter={24}>
            <Col span={8}>
              <FormItem
                label={messages('enterprise-manage.key23'/*法人*/)}  /* 法人*/
                colon={true}>
                {getFieldDecorator('legalEntityId', {
                  initialValue: companyDetail.legalEntityName,
                  rules: [
                    {
                      required: true,
                      message: messages("common.please.select")
                    },
                  ]
                })(
                  <Selector
                    onChange={this.legalEntityIdChange}
                    disabled={companyDetail.legalEntityId}
                    placeholder={messages("common.please.select")}
                    selectorItem={this.state.selectListLegalEntity}/>
                )
                }
              </FormItem>
            </Col>
            <Col span={8}>
              <FormItem
                label={messages('enterprise-manage.key28'/*上级公司*/)} /* 上级公司*/
                colon={true}>
                {getFieldDecorator('parentCompanyId', {
                  initialValue: companyDetail.parentCompanyName
                })(this.renderParentCompanyList(this.state.selectListParentCompany))
                }
              </FormItem>
            </Col>

            <Col span={8}>
              <FormItem
                label={messages('enterprise-manage.key351')/*所属国家*/}
                colon={true}>
                {getFieldDecorator('countryCode', {
                  initialValue: companyDetail.countryName,
                  rules: [
                    {
                      required: true,
                      message: messages("common.please.select")
                    },
                  ]
                })(
                  <Selector type='selectListCountryCode'
                            placeholder={messages("common.please.select")}
                            onChange={this.countryCodeChange}
                            showSearch
                  />
                )
                }
              </FormItem>
            </Col>
          </Row>
          <Row gutter={24} className="new-lp-row-wrap">
            <Col span={8}>
              <FormItem
                label={messages("common.column.status")}//状态
                colon={false}>
                {getFieldDecorator("enabled", {
                  initialValue: companyDetail.enabled,
                  valuePropName: 'checked',
                })
                (
                  <Switch
                    defaultChecked={companyDetail.enabled}
                    checked={companyDetail.enabled}
                    checkedChildren={<Icon type="check"/>}
                    unCheckedChildren={<Icon type="cross"/>}/>
                )
                }
              </FormItem>
            </Col>
            <Col span={8}>
              <FormItem
                label={
                  <span>
                   <span className="required-red">*&nbsp;</span>
                   <span>{messages('enterprise-manage.key29'/*有效日期从*/)}</span>
                </span>
                }//有效期从
                colon={true}>
                {getFieldDecorator('startDateActive', {
                  initialValue: companyDetail.startDateActive ? moment(companyDetail.startDateActive) : null,
                  rules: []
                })(
                  <div>
                    <DatePicker
                      value={companyDetail.startDateActive ? moment(companyDetail.startDateActive) : null}
                      onChange={this.onStartTimeChange}
                      disabledDate={this.disabledStartDate}
                    />
                  </div>
                )
                }
              </FormItem>
            </Col>
            <Col span={8}>
              <FormItem
                label={messages('enterprise-manage.key30'/*有效日期至*/)}//有效期到
                colon={true}>
                {getFieldDecorator('endDateActive', {
                  initialValue: companyDetail.endDateActive ? moment(companyDetail.endDateActive) : null,
                  rules: []
                })(
                  <div>
                    <DatePicker
                      value={companyDetail.endDateActive ? moment(companyDetail.endDateActive) : null}
                      onChange={this.onEndTimeChange}
                      disabledDate={this.disabledEndDate}
                    />
                  </div>
                )
                }
              </FormItem>
            </Col>
          </Row>
          <Row gutter={24} className="new-lp-row-wrap">
            <Col span={8}>
              <FormItem
                label={messages('enterprise-manage.key491'/*公司属性*/)} /* 公司属性*/
                colon={true}>
                {getFieldDecorator('companyAttribute', {
                  initialValue: companyDetail.companyAttribute === null ? undefined : companyDetail.companyAttribute ? 1 : 0,
                  rules: [
                    {
                      required: true,
                      message: messages("common.please.select"),
                    },
                  ],
                })(this.renderCompanyAttributeList())
                }
              </FormItem>
            </Col>
            <Col span={8}>
              {
                this.state.flag ?
                <FormItem
                  label={messages("enterprise-region.key1"/*区域*/)}//区域
                  colon={false}>
                  {getFieldDecorator("area", {
                    initialValue: companyDetail.area ? [{messageKey: companyDetail.area, id: companyDetail.area}] : [],
                  })
                  (
                    <Chooser
                      single
                      placeholder={messages('common.please.select')}
                      labelKey="messageKey"
                      valueKey="id"
                      onChange={this.onAreaChange}
                      type="area"
                    />
                  )
                  }
                </FormItem>:
                <FormItem
                  label={messages("enterprise-region.key1"/*区域*/)}//区域
                  colon={false}>
                  {getFieldDecorator("area", {
                    initialValue: companyDetail.area
                  })
                  (
                    <Input placeholder={messages("common.please.enter")}/>
                    )
                  }
                </FormItem>
              }
            </Col>
            <Col span={8}>
              {
                this.state.flag ?
                <FormItem
                  label={messages("enterprise-region.key2")}//市场
                  colon={false}>
                  {getFieldDecorator("market", {
                    initialValue: companyDetail.market ? [{messageKey: companyDetail.market, id: companyDetail.market}] : [],
                  })
                  (
                    <Chooser
                        single
                        placeholder={messages('common.please.select')}
                        labelKey="messageKey"
                        listExtraParams={{area:this.state.companyDetail.area}}
                        valueKey="id"
                        type="market"
                      />
                  )
                  }
                </FormItem>:
                <FormItem
                  label={messages("enterprise-region.key2")}//市场
                  colon={false}>
                  {getFieldDecorator("market", {
                    initialValue: companyDetail.market
                  })
                  (
                    <Input placeholder={messages("common.please.enter")}/>
                  )
                  }
                </FormItem>
              }
            </Col>
          </Row>
          <Row gutter={24} className="new-lp-row-wrap">
            <Col span={8}>
              <FormItem
                label={messages('enterprise-manage.key509'/*财务预审人员*/)}
                colon={true}>
                {getFieldDecorator('financialPreId', {
                  initialValue: companyDetail.financialPreId ? [
                    {
                      fullName: companyDetail.financialPreName,
                      employeeID: companyDetail.financialPreId
                    }
                  ] : [],
                  rules: []
                })(
                  <Chooser single={true}
                           placeholder={messages("common.please.select")}
                           labelKey="fullName"
                           valueKey="userOID"
                           onChange={(value) => this.handleFinancialPreSelect(value)}
                           listExtraParams={{employeeID:this.state.companyDetail.financialPreId}}
                           type="user"/>
                )}
              </FormItem>
            </Col>
            <Col span={8}>
              <FormItem
                label={messages('enterprise-manage.key510'/*财务复审人员*/)}
                colon={true}>
                {getFieldDecorator('financialReviewId', {
                  initialValue: companyDetail.financialReviewId ? [
                    {
                      fullName: companyDetail.financialReviewName,
                      employeeID: companyDetail.financialReviewId
                    }
                  ] : [],
                  rules: []
                })(
                  <Chooser single={true}
                           placeholder={messages("common.please.select")}
                           labelKey="fullName"
                           valueKey="userOID"
                           onChange={(value) => this.handleFinancialReviewSelect(value)}
                           listExtraParams={{employeeID:this.state.companyDetail.financialReviewId}}
                           type="user"/>
                )}
              </FormItem>
            </Col>
          </Row>
          <Row>
            <Col>
              <FormItem
                label={messages('enterprise-manage.key56'/*地址*/)}  /* 地址*/
                colon={true}>
                {getFieldDecorator("address", {
                  initialValue: companyDetail.address,
                  rules: []
                })(
                  <Input placeholder={messages("common.please.enter")}/>
                )
                }
              </FormItem>
            </Col>
          </Row>
          <Row>
              {this.renderExtendFiledEditing()}
          </Row>
          <div>
            <Button type="primary" loading={loading}
                    htmlType="submit">
              {messages("common.save") /*保存*/}
            </Button>
            <Button onClick={this.handleCancel}
                    style={{marginLeft: 8}}>
              {messages("common.cancel") /*取消*/}
            </Button>
          </div>
        </Form>
      </div>

    )
  }

}


WrappedNewCompanyMaintain.contextTypes = {
  router: React.PropTypes.object
};
function mapStateToProps(state) {
  return {
    profile: state.login.profile,
    user: state.login.user,
    tenantMode: state.main.tenantMode,
    company: state.login.company,
  }
}
const NewCompanyMaintain = Form.create()(WrappedNewCompanyMaintain);

export default connect(mapStateToProps)(NewCompanyMaintain);


